bitkeeper revision 1.1108.14.6 (410649f9zyS54Re8bSXNwM_nPxqrOw)
authormjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Tue, 27 Jul 2004 12:26:33 +0000 (12:26 +0000)
committermjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Tue, 27 Jul 2004 12:26:33 +0000 (12:26 +0000)
Add support for setting and getting domain maxmem.

tools/libxc/xc_domain.c
tools/python/xen/lowlevel/xc/xc.c
tools/python/xen/xend/XendClient.py
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/server/SrvDomain.py
tools/python/xen/xm/main.py

index 838418e0b72656be45842b78b955788254ee3fd2..d389757ceeda3e578711bc2c32399ae7b81de115 100644 (file)
@@ -105,7 +105,7 @@ int xc_domain_getinfo(int xc_handle,
             DOMFLAGS_SHUTDOWNMASK;
 
         info->nr_pages = op.u.getdomaininfo.tot_pages;
-        info->max_memkb = op.u.getdomaininfo.max_pages<<(PAGE_SHIFT-10);
+        info->max_memkb = op.u.getdomaininfo.max_pages<<(PAGE_SHIFT);
         info->shared_info_frame = op.u.getdomaininfo.shared_info_frame;
         info->cpu_time = op.u.getdomaininfo.cpu_time;
         strncpy(info->name, op.u.getdomaininfo.name, XC_DOMINFO_MAXNAME);
index 6e55853360c931bdc0d1a2417011f9f3bed6f271..21d40b026e94266d3509f759bcb3affd92a3d322 100644 (file)
@@ -906,15 +906,15 @@ static PyObject *pyxc_domain_setmaxmem(PyObject *self,
     XcObject *xc = (XcObject *)self;
 
     u32 dom;
-    unsigned long max_memkb;
+    unsigned long maxmem_kb;
 
-    static char *kwd_list[] = { "dom", "max_memkb", NULL };
+    static char *kwd_list[] = { "dom", "maxmem_kb", NULL };
 
     if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ii", kwd_list, 
-                                      &dom, &max_memkb) )
+                                      &dom, &maxmem_kb) )
         return NULL;
 
-    if ( xc_domain_setmaxmem(xc->xc_handle, dom, max_memkb) != 0 )
+    if ( xc_domain_setmaxmem(xc->xc_handle, dom, maxmem_kb) != 0 )
         return PyErr_SetFromErrno(xc_error);
     
     Py_INCREF(zero);
@@ -980,6 +980,7 @@ static PyMethodDef pyxc_methods[] = {
       " blocked  [int]:  Bool - is the domain blocked waiting for an event?\n"
       " running  [int]:  Bool - is the domain currently running?\n"
       " mem_kb   [int]:  Memory reservation, in kilobytes\n"
+      " maxmem_kb [int]: Maximum memory limit, in kilobytes\n"
       " cpu_time [long]: CPU time consumed, in nanoseconds\n"
       " name     [str]:  Identifying name\n"
       " shutdown_reason [int]: Numeric code from guest OS, explaining "
@@ -1228,7 +1229,7 @@ static PyMethodDef pyxc_methods[] = {
       METH_VARARGS | METH_KEYWORDS, "\n"
       "Set a domain's memory limit\n"
       " dom [int]: Identifier of domain.\n"
-      " max_memkb [long]: .\n"
+      " maxmem_kb [long]: .\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
     { NULL, NULL, 0, NULL }
index 8e8b2ba56d0dc1fc482e0cc247dc92db959c435f..3846fbce76c12e0ceb2831eda1b0a4234d72dd3c 100644 (file)
@@ -510,6 +510,11 @@ class Xend:
                               'latency' : latency,
                               'xtratime': xtratime })
 
+    def xend_domain_maxmem_set(self, id, memory):
+        return self.xendPost(self.domainurl(id),
+                             { 'op'     : 'maxmem_set',
+                               'memory' : memory })
+
     def xend_domain_vifs(self, id):
         return self.xendGet(self.domainurl(id),
                             { 'op'      : 'vifs' })
@@ -565,9 +570,6 @@ class Xend:
                              {'op'      : 'inject',
                               'event'   : fileof(sxpr) })
 
-    def xend_dmesg(self):
-        return self.xendGet(self.dmesgurl())
-
 def xendmain(srv, asynch, fn, args):
     if asynch:
         client = AsynchXendClientProtocol()
index 6f2ac9192830096d949081bce33d573bce341e9f..1e6a91a24432d195123b959c75b796d6b62bae12 100644 (file)
@@ -686,6 +686,17 @@ class XendDomain:
         dom = int(dom)
         return xc.shadow_control(dom, op)
 
+    def domain_maxmem_set(self, dom, mem):
+        """Set the memory limit for a domain.
+
+        @param dom: domain
+        @param mem: memory limit (in MB)
+        @return: 0 on success, -1 on error
+        """
+        dom = int(dom)
+        maxmem = int(mem) * 1024
+        return xc.domain_setmaxmem(dom, maxmem_kb = maxmem)
+
 
 def instance():
     """Singleton constructor. Use this instead of the class constructor.
index d855e8b005224f9d6787a4bb1c8d9f83bbd1a96c..9d7dfe325ccf216a4dba078f79ac00aae6bc7a99 100644 (file)
@@ -408,12 +408,13 @@ class XendDomainInfo:
                 ['memory', self.memory] ]
 
         if self.info:
-            run   = (self.info['running'] and 'r') or '-'
-            block = (self.info['blocked'] and 'b') or '-'
-            stop  = (self.info['paused']  and 'p') or '-'
-            susp  = (self.info['shutdown'] and 's') or '-'
-            crash = (self.info['crashed'] and 'c') or '-'
-            state = run + block + stop + susp + crash
+            sxpr.append(['maxmem', self.info['maxmem_kb']/1024 ])
+            run   = (self.info['running']  and 'r') or '-'
+            block = (self.info['blocked']  and 'b') or '-'
+            pause = (self.info['paused']   and 'p') or '-'
+            shut  = (self.info['shutdown'] and 's') or '-'
+            crash = (self.info['crashed']  and 'c') or '-'
+            state = run + block + pause + shut + crash
             sxpr.append(['state', state])
             if self.info['shutdown']:
                 reason = shutdown_reason(self.info['shutdown_reason'])
index 8eb5e127197494092981d64d8d012082759ee261..886021ee75c1d42107c0d5bd2606bfa0da452e34 100644 (file)
@@ -151,6 +151,13 @@ class SrvDomain(SrvDir):
         val = fn(req.args, {'dom': self.dom.id})
         return val
 
+    def op_maxmem_set(self, op, req):
+        fn = FormFn(self.xd.domain_maxmem_set,
+                    [['dom', 'int'],
+                     ['memory', 'int']])
+        val = fn(req.args, {'dom': self.dom.id})
+        return val
+
     def op_vifs(self, op, req):
         return self.xd.domain_vif_ls(self.dom.id)
 
index 0e86572ed12a162ec04548229694e6620bdcbcae..d282193c432c078af2b9fa729aafa6ed729e4dd3 100644 (file)
@@ -351,6 +351,22 @@ class ProgPincpu(Prog):
 
 xm.prog(ProgPincpu)
 
+class ProgMaxmem(Prog):
+    group = 'domain'
+    name = 'maxmem'
+    info = """Set domain memory limit."""
+
+    def help(self, args):
+        print args[0], "DOM MEMORY"
+        print "\nSet the memory limit for domain DOM to MEMORY megabytes."
+
+    def main(self, args):
+        if len(args) != 3: self.err("%s: Invalid argument(s)" % args[0])
+        v = map(int, args[1:3])
+        server.xend_domain_maxmem_set(*v)
+
+xm.prog(ProgMaxmem)
+
 class ProgBvt(Prog):
     group = 'scheduler'
     name = "bvt"
@@ -529,7 +545,7 @@ class ProgDmesg(Prog):
     info  = """Print Xen boot output."""
 
     def main(self, args):
-        print server.xend_dmesg()[1]
+        print server.xend_node_dmesg()[1]
 
 xm.prog(ProgDmesg)